"""
@author: huangll
@email: ll.huang@hzgosun.com
@time: 2019/7/23 15:56

运维配置的自动化测试用例编写
"""

import unittest
from time import sleep

from common.functions import save_screenshot
from common.decorators import mkdir_classname, log4gs
from common.settings import TAG
from pages.operationMaintenancePage import OperationMaintenancePage


@log4gs
@mkdir_classname(TAG)
class OperationMaintenanceTest(unittest.TestCase):
    """运维配置页面校验"""
    @classmethod
    def setUpClass(cls):
        cls.log.info('=' * 30 + "开始运维配置页面测试({})".format(__class__.__name__) + '=' * 30)
        cls.page = OperationMaintenancePage('/DataManage/OperationMaintenance')

    @classmethod
    def tearDownClass(cls):
        cls.log.info('=' * 30 + "结束运维配置页面测试({})".format(__class__.__name__) + '=' * 30)
        cls.page.driver.quit()

    def setUp(self):
        self.log.info('>>>>>开始执行用例：{} {}'.format(self.id(), self.shortDescription()))
        sleep(1)

    def tearDown(self):
        self.log.info('<<<<<结束执行用例：{} {}'.format(self.id(), self.shortDescription()))


    #@unittest.skip
    def test_1_platformConfig(self):
        """平台资源配置"""
        try:
            sleep(1)
            self.page.platform_server_number.clear()
            self.page.platform_server_number.send_keys("2")  # 服务器数量配置
            self.page.platform_cpu_number.clear()
            self.page.platform_cpu_number.send_keys("3")  # CPU数量配置
            self.page.platform_RAM_number.clear()
            self.page.platform_RAM_number.send_keys("4")  # RAM内存容量配置
            self.page.platform_disk_number.clear()
            self.page.platform_disk_number.send_keys("5")  # 硬盘容量配置
            self.page.a_btn.click()
            sleep(1)
            result = self.page.check_success.text
            self.assertEqual(result, "应用成功")
        except Exception as e:
            print("平台资源配置失败：%r" % e)
            save_screenshot(self,"平台资源配置失败")

    #@unittest.skip
    def test_1_platformConfig_f(self):
        """平台资源配置无效值校验"""
        try:
            numbers = ["2","数字","Qwe","!@#"]
            self.page.platform_server_number.clear()
            self.page.platform_server_number.send_keys("数字")   #
            result = self.page.platform_server_number_invalid.text
            self.assertEqual(result, "0-99999999之间的整数")
            self.log.info(result)
        except Exception as e:
            print("平台资源配置无效值校验失败：%r" % e)

    #@unittest.skip
    def test_2_dataConfig(self):
        """数据资源配置"""
        try:
            self.page.data_server_number.clear()
            self.page.data_server_number.send_keys("6")
            self.page.data_cpu_number.clear()
            self.page.data_cpu_number.send_keys("7")
            self.page.data_RAM_number.clear()
            self.page.data_RAM_number.send_keys("8")
            self.page.data_disk_number.clear()
            self.page.data_disk_number.send_keys("9")
            self.page.a_btn.click()
            result = self.page.check_success.text
            self.assertEqual(result, "应用成功")
        except Exception as e:
            print("数据资源配置输入框校验失败：%r" % e)
            save_screenshot(self,"数据资源配置失败")

    #@unittest.skip
    def test_3_hardwareConfig(self):
        """相机报送异常配置"""
        try:
            self.page.less_report_selected.click()  # 报送太少取消勾选
            sleep(1)
            self.page.less_report_selected.click()  # 报送太少再次勾选
            self.page.less_report_input.clear()
            self.page.less_report_input.send_keys("2")
            self.page.many_report_selected.click()  # 报送太多取消勾选
            sleep(1)
            self.page.many_report_selected.click()  # 报送太多再次勾选
            sleep(1)
            self.page.many_report_input.clear()
            self.page.many_report_input.send_keys("500")
            self.page.no_report_selected.click()  # 数据未报送取消勾选
            sleep(1)
            self.page.no_report_selected.click()  # 数据未报送再次勾选
            self.page.a_btn.click()
            sleep(1)
            result = self.page.check_success.text
            self.assertEqual(result, "应用成功")
        except Exception as e:
            print("相机报送异常配置输入框校验失败：%r" % e)
            save_screenshot(self,"相机报送异常配置失败")

    #@unittest.skip
    def test_4_deviceConfig(self):
        """设备展示配置"""
        try:
            # 相机数据勾选
            self.page.camera_yesterday.click()
            sleep(1)
            self.page.camera_yesterday.click()
            self.page.camera_before_yesterday.click()
            # 手环数据勾选
            self.page.wristband_yesterday.click()
            sleep(1)
            self.page.wristband_yesterday.click()
            self.page.wristband_before_yesterday.click()
            # 电围数据勾选
            self.page.elefence_yesterday.click()
            sleep(1)
            self.page.elefence_yesterday.click()
            self.page.elefence_before_yesterday.click()
            self.page.a_btn.click()
            sleep(1)
            result = self.page.check_success.text
            self.assertEqual(result, "应用成功")
        except Exception as e:
            print("设备展示配置校验失败：%r" % e)
            save_screenshot(self,"设备展示配置失败")


if __name__ == '__main__':
    unittest.main()